Quickstart Guide
Provided in this page is a quick and simple introduction to Git and a tutorial on setting up a simple repository. While the example provided is simple, learning the fundamentals is necessary to be able to understand more complex concepts. Installation To begin using Git, one must first install the client-side application. The application can be found on the official Git website in the downloads section. Download and install the file appropriate to the intended Operating System. The video on the right will demonstrate in detail how to install Git on Windows, but a similar method will be used to install on MacOS or on a LinuxOS. Creating Your First Repository To begin using Git, the first step is to create a repository. While everything in Git can be done using the command line, several additional tool have been created to aid in managing repositories. The most popular tool for this is called GitHub. GitHub is a website which hosts remote repositories and allows for visual creation and management of repositories. Create a Local Repository To start creating a new repository, on a local machine initialize a new repository. This can be done by navigating the the directory where all local files will be stored. the Git command prompt will then be opened at this location and the following command will initialize a new, empty repository. git init Making Changes to Your Repository After the repository has been initialized changes can now be made to it. To start out any existing files to be included can be done so by using the following command. git add (filename) Changes to the added files will now be tracked by Git. After satisfied with the changes, it is time to commit those changes to the current branch. The changes made can be committed by using the following command. git commit A message can be attached to the commit be appending the "-m" flag and a message enclosed in double quotes git commit -m "your message here" Adding A Remote to Your Repository Now that a local repository has been created, a remote repository can be added. While this remote can be stored in many places, using GitHub has become a common practice. By signing in to GitHub, the "new repository" button can be clicked. The repository can be given a name a description. Linking the Local and Remote Repositories After the remote has been created, under the "clone or download" menu, copy the URL ending in ".git". This can now be used to add this repository as a remote to the local repository using the following command in the Git terminal. git remote add origin (URL) Now, the local changes can be applied to the remote repository using the following command. git push -u origin master Adding a New Branch to Your Repository Now that you are able to make changes to a repository, you can now begin to work with branches. To start a new local branch can be created using the following command. git checkout -b (branch name) This will create a new branch with with same name by copying the files in the current branch and set the new branch as the active branch. Now, new changes will be committed to that branch. To add these changes to the remote repository, the following command can be used. git push origin (branch name) Merging Branches in your Remote Now that work has been committed on multiple branches, when it is time to assimilate the changes back into the master branch, it is time to merge. First, the branch to merge should be checked out locally. git checkout (branch name) Now the merge can be performed. In this example, the active branch will be merged with the remote master. git merge origin/master To complete the merge the changes should now be pushed to the remote repository in the usual manner. git push origin master Closing Notes Now that the basics of repository creation and management have been covered, you should be able to work on simple projects. For more advanced management techniques or when working as a team, a strict paradigm is the only way to assure a clean working environment. Many other Git tutorials exist which go into great detail about each aspect of usage. Additionally, the official Git website contains tutorial videos and reference material indispensable to the Git developer.